package com.java110.mall.shop.bmo.shopVipUser.impl;

import com.java110.core.annotation.Java110Transactional;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.intf.acct.IShopVipAccountInnerServiceSMO;
import com.java110.intf.shop.IShopVipUserInnerServiceSMO;
import com.java110.po.shop.ShopVipAccountPo;
import com.java110.po.shop.ShopVipUserPo;
import com.java110.mall.shop.bmo.shopVipUser.ISaveShopVipUserBMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service("saveShopVipUserBMOImpl")
public class SaveShopVipUserBMOImpl implements ISaveShopVipUserBMO {

    @Autowired
    private IShopVipUserInnerServiceSMO shopVipUserInnerServiceSMOImpl;

    @Autowired
    private IShopVipAccountInnerServiceSMO shopVipAccountInnerServiceSMOImpl;

    /**
     * 添加小区信息
     *
     * @param shopVipUserPo
     * @return 订单服务能够接受的报文
     */
    @Java110Transactional
    public ResponseEntity<String> save(ShopVipUserPo shopVipUserPo) {

        shopVipUserPo.setVipId(GenerateCodeFactory.getGeneratorId("11"));
        int flag = shopVipUserInnerServiceSMOImpl.saveShopVipUser(shopVipUserPo);

        if (flag < 1) {
            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "保存失败");
        }

        //新建会员账号
        ShopVipAccountPo shopVipAccountPo = new ShopVipAccountPo();
        shopVipAccountPo.setAcctName(shopVipUserPo.getVipName());
        shopVipAccountPo.setAcctType("2004");
        shopVipAccountPo.setAmount("0");
        shopVipAccountPo.setShopId(shopVipUserPo.getShopId());
        shopVipAccountPo.setStoreId(shopVipUserPo.getStoreId());
        shopVipAccountPo.setVipAcctId(GenerateCodeFactory.getGeneratorId("11"));
        shopVipAccountPo.setVipId(shopVipUserPo.getVipId());
        flag = shopVipAccountInnerServiceSMOImpl.saveShopVipAccount(shopVipAccountPo);
        if (flag < 1) {
            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "保存失败");
        }
        return ResultVo.createResponseEntity(ResultVo.CODE_OK, "保存成功");
    }

}
